﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using Hydra.Shell;

namespace Hydra.Shell.Implementations
{
    public class CommandSet<TGroup> : Dictionary<uint, CommandInfo>
    {
        public Guid CommandGroup { get; private set; }

        public CommandSet()
        {
            this.CommandGroup = typeof(TGroup).GetGuid();
        }

        public bool HasCommand(uint command)
        {
            return this.ContainsKey(command);
        }

        public bool HasCommand(uint command, out CommandInfo commandInfo)
        {
            if (this.ContainsKey(command))
            {
                commandInfo = base[command];
                return true;
            }
            else
            {
                commandInfo = null;
                return false;
            }
        }

        public bool NeedsText(uint command)
        {
            if (this.ContainsKey(command))
            {
                var commandInfo = base[command];

                return commandInfo.QueryCommandText;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// This should never be called from a GetCommands function implementation.  GetCommands should only fill what is in this set
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public CommandInfo this[uint command]
        {
            get
            {
                if (!this.ContainsKey(command))
                {
                    this.Add(command, new CommandInfo(command));
                }

                return base[command];
            }
        }
    }
}
